/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vn.com.sml.SEFM.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.support.PagedListHolder;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.mvc.SimpleFormController;
import vn.com.sml.SEFM.BUS.IPBlackBUS;
import vn.com.sml.SEFM.domain.Ipblacklist;
import vn.com.sml.SEFM.domain.Ip;
/**
 *
 * @author Tunp
 */
public class IPBlackController extends SimpleFormController implements Controller{
    private IPBlackBUS ipblackBUS = new IPBlackBUS();

    public void setipblackBUS(IPBlackBUS ipblackBUS) {
        this.ipblackBUS = ipblackBUS;
    }
    public IPBlackController() {
        //Initialize controller properties here or 
        //in the Web Application Context

//        setCommandClass(IP.class);
//        setCommandName("IP");
//        setSuccessView("DetailIP");
//        setFormView("ListIPs");
    }
    
       
    @Override
	public ModelAndView handleRequest(HttpServletRequest arg0,
			HttpServletResponse arg1) throws Exception {
                
                // Box Search
                String search_col = (arg0.getParameter("search_col"));
                String search_content = (arg0.getParameter("search_text"));
                
                //Remove blacklist
                String blackIdremove = (arg0.getParameter("blackIdremove"));
                
                if(blackIdremove!=null) {
                    ipblackBUS.DeleteBlackIP(Integer.parseInt(blackIdremove));
                }

                    List<Ipblacklist> listBlackIP = null;
                    if(search_content != null)
                    {
                        listBlackIP = ipblackBUS.listIpblacklist(search_col,search_content);
                    }
                    else
                    {
                        listBlackIP = ipblackBUS.listIpblacklist();
                    }
                    ModelAndView modelAndView = new ModelAndView("ListBlackIP");
                    modelAndView.addObject("listBlackIP", listBlackIP);
                    
                    return modelAndView;
                
	}

//     @Override
//    protected void doSubmitAction(Object command) throws Exception {
//        throw new UnsupportedOperationException("Not yet implemented");
//    }

    //Use onSubmit instead of doSubmitAction 
    //when you need access to the Request, Response, or BindException objects
    /*
    @Override
    protected ModelAndView onSubmit(
    HttpServletRequest request, 
    HttpServletResponse response, 
    Object command, 
    BindException errors) throws Exception {
    ModelAndView mv = new ModelAndView("DetailIP");
    //Do something...

    
    return mv;
    }
     */
}

